/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.trade.service;

import java.util.ArrayList;
import java.util.List;

import com.jeeplus.modules.goods.entity.Goods;
import com.jeeplus.modules.goods.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.trade.entity.Trade;
import com.jeeplus.modules.trade.mapper.TradeMapper;

/**
 * 交易记录Service
 * @author w
 * @version 2020-10-08
 */
@Service
@Transactional(readOnly = true)
public class TradeService extends CrudService<TradeMapper, Trade> {
	@Autowired
	private GoodsService goodsService;

	public Trade get(String id) {
		return super.get(id);
	}
	
	public List<Trade> findList(Trade trade) {
		return super.findList(trade);
	}
	
	public Page<Trade> findPage(Page<Trade> page, Trade trade) {
		dataRuleFilter(trade);
		trade.setPage(page);
		List<Trade> list = mapper.findFinishList(trade);
		for (Trade trade1 : list) {
			trade1.setGoodsId(trade1.getGoods().getId());
			Goods goods = goodsService.get(trade1.getGoods().getId());
			trade1.setGoodsType(goods.getGoodsType());
		}
		page.setList(list);
		return page;
	}

	public Page<Trade> findPages(Page<Trade> page, Trade trade) {
		dataRuleFilter(trade);
		trade.setPage(page);
		List<Trade> list = mapper.findFinishList(trade);
		for (Trade trade1 : list) {
			trade1.setGoodsId(trade1.getGoods().getName());
			trade1.setPrice("");
			Goods goods = goodsService.get(trade1.getGoods().getId());
			trade1.setGoodsType(goods.getGoodsType());
		}
		page.setList(list);
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(Trade trade) {
		super.save(trade);
	}
	
	@Transactional(readOnly = false)
	public void delete(Trade trade) {
		super.delete(trade);
	}
	
}